# routers/users.py
import logging
from fastapi import APIRouter, Depends

from schema_base import PageInationResult
from http_base import unified_resp
from ..schemas.system_user import (
    UserListIn, UserDetailIn, UserAddIn, UserEditIn, UserDelIn, UserOut
)
from ..service.system.system_user import IUserService

logger = logging.getLogger(__name__)
router = APIRouter(prefix="/users")


@router.post("/list", response_model=PageInationResult[UserOut], summary="用户列表")
@unified_resp
async def user_list(list_in: UserListIn, user_service: IUserService = Depends()):
    return await user_service.list(list_in)


@router.get("/detail", summary="用户详情")
@unified_resp
async def user_detail(detail_in: UserDetailIn = Depends(), user_service: IUserService = Depends()):
    return await user_service.detail(detail_in.id)


@router.post("/add", summary="新增用户")
@unified_resp
async def user_add(add_in: UserAddIn, user_service: IUserService = Depends()):
    return await user_service.add(add_in)


@router.post("/edit", summary="编辑用户")
@unified_resp
async def user_edit(edit_in: UserEditIn, user_service: IUserService = Depends()):
    return await user_service.edit(edit_in)


@router.post("/del", summary="删除用户")
@unified_resp
async def user_del(del_in: UserDelIn, user_service: IUserService = Depends()):
    return await user_service.delete(del_in.id)


@router.post("/all", response_model=PageInationResult[UserOut], summary="全部用户")
@unified_resp
async def user_all(list_in: UserListIn, user_service: IUserService = Depends()):
    return await user_service.all(list_in)
